package com.blog.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.blog.bean.Discuss;
import com.blog.bean.User;
import com.blog.dao.IDiscussDao;
import com.blog.dao.IUserDao;

/**
 * @className: DiscussController
 * @description: 
 * @author: HCl
 * @createTime: 2020年6月9日 上午2:39:43
 */
@Controller
public class DiscussController {
	
	@Autowired
	private IUserDao userDao;
	@Autowired
	private IDiscussDao discussDao;
	
	@RequestMapping(value = "addDiscuss")
	@ResponseBody
	public Map<String, Object> addDiscuss(HttpSession session,HttpServletRequest request){
		Map<String, Object> reMap = new HashMap<String, Object>();
		User user = (User)session.getAttribute("loginUser");
		Discuss discuss = new Discuss();
		
		discuss.setObjectid(Integer.parseInt(request.getParameter("objectid")));
		discuss.setUserid(user.getId());
		discuss.setNum(1);
		discuss.setObjecttype(1);
		discuss.setTime(request.getParameter("time"));
		discuss.setContent(request.getParameter("content"));
		discuss.setState(1);
		int i = discussDao.addBlogDiscuss(discuss);
		
		return reMap;
		
	}

	@RequestMapping(value = "deleteDiscuss")
	@ResponseBody
	public Map<String, Object> deleteDiscuss(HttpSession session,HttpServletRequest request){
		Map<String, Object> reMap = new HashMap<String, Object>();
		User user = (User)session.getAttribute("loginUser");
		Discuss discuss = new Discuss();
		discuss.setId(0);
		try {
			discuss.setId(Integer.parseInt(request.getParameter("discussid")));
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
		int i = discussDao.deleteDiscussById(discuss.getId());
		
		return reMap;
		
	}
}
